from django.db import models
from datetime import datetime

# Create your models here.


class virus_record(models.Model):
    # ID
    id = models.AutoField(verbose_name='序号', primary_key=True)
    # 笔记本IP地址
    pcip = models.CharField(verbose_name='IP地址',
                            max_length=128, blank=True, null=True)
    # 用户姓名
    username = models.CharField(
        max_length=30, verbose_name='姓名', blank=True, null=True)
    # 笔记本编号
    number = models.CharField(
        max_length=30, verbose_name='编号', blank=True, null=True)
    # 计算机名
    pcname = models.CharField(
        max_length=30, verbose_name='计算机名', blank=True, null=True)
    # 处理情况
    status = models.CharField(
        max_length=20, verbose_name='处理情况', blank=True, null=True)
    # 处理时间
    handle_time = models.DateField(verbose_name='处理时间', blank=True, null=True)
    # 备注
    remarks = models.CharField(
        max_length=100, verbose_name='备注', blank=True, null=True)
    # 病毒种类
    virus_type = models.CharField(max_length=100,
                                  verbose_name='病毒种类', blank=True, null=True, default='挖矿病毒')
    # MAC地址
    pcmac = models.CharField(
        max_length=50, verbose_name='MAC', blank=True, null=True)

    class Meta:
        verbose_name = '病毒记录表'
        verbose_name_plural = verbose_name


def __str__(self):
    return self.name


class mail_info(models.Model):
    # 用户姓名
    username = models.ForeignKey(
        virus_record, on_delete=models.CASCADE, verbose_name='姓名')
    # 邮箱
    usermail = models.CharField(max_length=100, verbose_name='邮箱')

    class Meta:
        verbose_name = '用户邮箱表'
        verbose_name_plural = verbose_name


def __str__(self):
    return self.name


class asset(models.Model):
    # ID
    id = models.AutoField(verbose_name='序号', primary_key=True)
    #添加时间
    #add_time = models.DateTimeField(verbose_name='添加时间',auto_now_add=True,null=True)
    # 是否完成
    Finish = models.CharField(
        max_length=20, verbose_name='是否完成', blank=True, null=True)
    # 需求来源
    Source = models.CharField(
        max_length=30, verbose_name='需求来源', blank=True, null=True)
    # 单据号
    Document_No = models.CharField(
        max_length=50, verbose_name='单据号', blank=True, null=True)
    # 采购订单号
    Order_No = models.CharField(
        max_length=50, verbose_name='采购订单号', blank=True, null=True)
    # 请购日期
    Requisition_date = models.CharField(max_length=50,
        verbose_name='请购日期', blank=True, null=True)
    # 请购物资/固定资产
    Materials = models.CharField(max_length=300,
                                 verbose_name='请购物资/固定资产', blank=True, null=True)
    # 请购部门
    Department = models.CharField(
        max_length=50, verbose_name='请购部门', blank=True, null=True)
    # 请购人
    Requisitioner = models.CharField(
        max_length=30, verbose_name='请购人', blank=True, null=True)
    # 请购数量
    Requisition_Num = models.CharField(max_length=20,
                                       verbose_name='请购数量', blank=True, null=True)
    # 请购用途
    Requisition_purpose = models.CharField(max_length=300,
                                           verbose_name='请购用途', blank=True, null=True)
    # 采购订单生成时间
    Order_Time = models.CharField(max_length=50,
        verbose_name='采购订单生成时间', blank=True, null=True)
    # 采购员
    Purchaser = models.CharField(
        max_length=30, verbose_name='采购员', blank=True, null=True)
    # 超长原因说明
    Reason = models.CharField(
        max_length=300, verbose_name='超长原因说明', blank=True, null=True)
    # 供应商
    Supplier = models.CharField(
        max_length=100, verbose_name='供应商', blank=True, null=True)
    # 预计到货时间（采购回复）
    Arrival_time1 = models.CharField(max_length=50,
        verbose_name='预计到货时间（采购回复）', blank=True, null=True)
    # 预计到货时间（供应商回复）
    Arrival_time2 = models.CharField(max_length=50,
        verbose_name='预计到货时间（供应商回复）', blank=True, null=True)
    # 实际到货时间（一）
    Actual_time1 = models.CharField(max_length=50,
        verbose_name='实际到货时间（一）', blank=True, null=True)
    # 实际到货数量（一）
    Actual_Num1 = models.CharField(max_length=20,
                                   verbose_name='实际到货数量（一）', blank=True, null=True)
    # 实际到货时间（二）
    Actual_time2 = models.CharField(max_length=50,
        verbose_name='实际到货时间（二）', blank=True, null=True)
    # 实际到货数量（二）
    Actual_Num2 = models.CharField(max_length=20,
                                   verbose_name='实际到货数量（二）', blank=True, null=True)
    # 实际到货时间（三）
    Actual_time3 = models.CharField(max_length=50,
        verbose_name='实际到货时间（三）', blank=True, null=True)
    # 实际到货数量（三）
    Actual_Num3 = models.CharField(max_length=20,
                                   verbose_name='实际到货数量（三）', blank=True, null=True)
    # 未到数量
    Unarrival_Num = models.CharField(max_length=20,
                                     verbose_name='未到数量', blank=True, null=True)
    # 是否超期
    Overdue = models.CharField(
        max_length=20, verbose_name='是否超期', blank=True, null=True)
    # 超期时间
    Overdue_time = models.CharField(
        max_length=20, verbose_name='超期时间', blank=True, null=True)
    # 备注
    Remarks = models.CharField(
        max_length=300, verbose_name='备注', blank=True, null=True)

    class Meta:
        verbose_name = '资产请购表'
        verbose_name_plural = verbose_name


def __str__(self):
    return self.name


class userinfo(models.Model):
    '''用户表'''

    gender = (
        ('male', '男'),
        ('female', '女'),
    )

    # 姓名
    name = models.CharField(max_length=128, unique=True)
    # 用户号
    username = models.CharField(max_length=32, unique=True, default="")
    # 密码
    password = models.CharField(max_length=256)
    # 性别
    sex = models.CharField(max_length=32, choices=gender, default='男')
    # 创建时间
    c_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name

    class Meta:
        ordering = ['c_time']
        verbose_name = '用户表'
        verbose_name_plural = verbose_name


class brand(models.Model):
    '''品牌'''
    #uniqueid
    id = models.AutoField(verbose_name='序号', primary_key=True)
    #品牌
    brand_name = models.CharField(max_length=50, verbose_name='品牌', blank=False, null=False)

class department(models.Model):
    '''部门'''
    #uniqueid
    id = models.AutoField(verbose_name='序号', primary_key=True)
    #部门名称
    department_name = models.CharField(max_length=50,verbose_name='部门',blank=False,null=False)

class pctype(models.Model):
    '''计算机类型'''
    gender = (
        ('notebook','笔记本'),
        ('pc','台式机'),
        )
    #uniqueid
    id = models.AutoField(verbose_name='序号', primary_key=True)
    #品牌
    brand = models.ForeignKey(brand,related_name='brand',on_delete=models.DO_NOTHING, verbose_name='品牌')
    #电脑类型
    tpye = models.CharField(max_length=30, choices=gender, default='null',verbose_name='电脑类型')
    #型号
    pc_model = models.CharField(max_length=200,verbose_name='型号',blank=False,null=False)
    #配置
    configuration = models.CharField(max_length=200,verbose_name='配置',blank=False,null=False)


class pcassets(models.Model):
    '''固定资产'''
    #固定资产编码
    pcassets_num = models.CharField(verbose_name='固定资产编码',primary_key=True,max_length=50)
    #电脑类型
    tpye = models.ForeignKey(pctype,related_name='pcassets_tpye',on_delete=models.DO_NOTHING,verbose_name='电脑类型')
    #型号
    pc_model = models.ForeignKey(pctype,related_name='pcassets_pc_model',on_delete=models.DO_NOTHING,verbose_name='型号')
    #配置
    configuration = models.ForeignKey(pctype,related_name='pcassets_configuration',on_delete=models.DO_NOTHING,verbose_name='配置')
    #品牌
    brand = models.ForeignKey(brand,related_name='pcassets_brand',on_delete=models.DO_NOTHING,verbose_name='品牌')
    #部门
    department_name = models.ForeignKey(department,related_name='pcassets_department_name',on_delete=models.DO_NOTHING,verbose_name='部门')
    #订单号？
    Order_No = models.ForeignKey(asset,related_name='pcassets_Order_No',on_delete=models.DO_NOTHING,verbose_name='订单号')
    #供应商
    Supplier = models.ForeignKey(asset,related_name='pcassets_Supplier',on_delete=models.DO_NOTHING,verbose_name='供应商')
    #信息部编码
    itcode = models.CharField(verbose_name='信息部编码',max_length=50,blank=False, null=False)
    #SN号
    sn_num = models.CharField(verbose_name='SN号',max_length=50,blank=False, null=False)
    #申请编号
    apply_num = models.CharField(verbose_name='申请编号',max_length=100,blank=False,null=False)

class transfer(models.Model):
    '''资产转移记录'''
    #使用人
    pc_user = models.CharField(verbose_name='使用人',primary_key=True,max_length=50)
    #信息部编码
    itcode = models.ForeignKey(pcassets,on_delete=models.DO_NOTHING,verbose_name='信息部编码')
    #部门
    department = models.ForeignKey(department,on_delete=models.DO_NOTHING,verbose_name='部门')
    #转移记录
    transfer_record = models.CharField(max_length=200,verbose_name='转移记录',blank=False, null=False)
    #转移时间
    transfer_time = models.DateTimeField(verbose_name='添加时间',auto_now_add=True,null=False)